﻿@model PostDetailsViewModel
           
@{
    ViewBag.Title = Model.Post.Title;
}

@section head {
    @if (@SiteConfiguration.SocialNetworkingSupport)
    { 
        <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script>
    }
    <script type="text/javascript">
        $(document).ready(function () {
            $(".approveComment").click(function () {
                var link = $(this);
                var id = link.attr("id");
                var container = $(this).parents(".comment_container");
                $.post("/Comment/Approve/", { commentID: id }, function (obj) {
                    if (obj.Success == true) {
                        link.html('@Html.Raw(Strings.Approved)!');
                        link.contents().unwrap();

                    }
                    else {
                        alert(obj.Message);
                    }
                });
            });

            $(".deleteComment").click(function () {
                var id = $(this).attr("id");
                var container = $(this).parents(".comment_container");
                var message = '@Strings.Comment_ConfirmDeleteString';
                if (confirm(message) == false)
                    return;

                $.post("/Comment/Delete/", { commentID: id }, function (obj) {
                    if (obj.Success == true)
                        container.remove();
                    else {
                        alert(obj.Message);
                    }
                });
            });
        });
    </script>
}
@Html.DisplayFor(m => Model.Post)
<!-- related posts go here -->
<br />
<div class="title">@Strings.Comments</div>
<div id="Comments">
</div>
<div id="post_comments">
    @{ foreach (var c in Model.ApprovedComments)
       { 
        @Html.DisplayFor(x => c)		
       } }
</div>
<br />
@if (Model.Post.AreCommentsEnabled)
{
<div id="commentForm">
    @using (Html.BeginForm(new { id = Model.Post.PostId }))
    {
        @Html.ValidationSummary(true)        
        <fieldset>
            <div class="editor-label">
                <label for="Comment_Author">@Strings.Name</label>
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.Comment.Author)
                @Html.ValidationMessageFor(model => model.Comment.Author)
            </div>
            <div class="editor-label">
                <label for="Comment_Email">@Strings.Email</label>
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.Comment.Email, new { size = 40 })
                @Html.ValidationMessageFor(model => model.Comment.Email)
            </div>
            <div class="editor-label">
                <label for="Comment_Website">@Strings.Website</label>
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.Comment.Website, new { size = 40 })
                @Html.ValidationMessageFor(model => model.Comment.Website)
            </div>
            <div class="editor-label">
                <label for="Comment_Content">@Strings.Message</label>
            </div>
            <div class="editor-field">
                @Html.TextAreaFor(model => model.Comment.Content, new { cols = 50, rows = 8 })
                @Html.ValidationMessageFor(model => model.Comment.Content)
            </div>
            <p>
                <input type="submit" value="@Strings.Save" /></p>
        </fieldset>
    }
</div>
}